#include "InputManager.h"

InputManager::InputManager()
{
	
	_registeredKeys[KeyActions::MoveLeft] = { sf::Keyboard::Left, false, false, false };
	_registeredKeys[KeyActions::MoveRight] = { sf::Keyboard::Right, false, false, false };
	_registeredKeys[KeyActions::MoveUp] = { sf::Keyboard::Up, false, false, false };
	_registeredKeys[KeyActions::MoveDown] = { sf::Keyboard::Down, false, false, false };
	
}


void InputManager::Update()
{
	std::map<KeyActions, _ActionStates>::const_iterator itr = _registeredKeys.begin();
	while(itr != _registeredKeys.end())
	{
		bool prevState = itr->second.currentState;
		bool currentState = sf::Keyboard::isKeyPressed(itr->second.key);
		bool pressedState = !prevState && currentState;
		_registeredKeys[itr->first] = { itr->second.key, prevState, currentState, pressedState };
		itr++;
	}
	
}

bool InputManager::KeyPressed(KeyActions action)
{
	return _registeredKeys[action].currentState;
}

bool InputManager::KeyDown(KeyActions action)
{
	return _registeredKeys[action].currentState;
}
